package com.woniuxy.project115.kaer.tenant.controller;


import cn.hutool.core.bean.BeanUtil;
import com.woniuxy.project115.kaer.commons.util.Result;
import com.woniuxy.project115.kaer.tenant.form.AppointmentItemForm;

import com.woniuxy.project115.kaer.tenant.param.AppointmentItemParam;
import com.woniuxy.project115.kaer.tenant.service.AppointmentItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author HuH
 * @since 2025年02月18日
 */
@RestController
@RequestMapping("/appointmentItem")
@Api(tags = "服务预约项目接口")
public class AppointmentItemController {
    @Resource
    private AppointmentItemService appointmentItemService;

    @PostMapping("/modifyAppointmentItem")
    @ApiOperation("修改服务预约项目")
    public Result modifyAppointmentItem(@RequestBody AppointmentItemForm form) throws Exception {
        appointmentItemService.modifyAppointmentItem(BeanUtil.toBean(form, AppointmentItemParam.class));
        return Result.succeed("修改成功");
    }

    @PostMapping("/addAppointmentItem")
    @ApiOperation("新增服务预约项目")
    public Result addAppointmentItem(@RequestBody AppointmentItemForm form) throws Exception {
        appointmentItemService.addAppointmentItem(BeanUtil.toBean(form, AppointmentItemParam.class));
        return Result.succeed("新增成功");
    }

    @PostMapping("/removeAppointmentItem")
    @ApiOperation("删除服务预约项目")
    @ApiImplicitParam(name = "itemId", value = "服务预约项目id")
    public Result removeAppointmentItem(Integer itemId) throws Exception {
        appointmentItemService.removeAppointmentItem(itemId);
        return Result.succeed("删除成功");
    }

    @PostMapping("/getAppointmentItem")
    @ApiOperation("获取服务预约项目")
    @ApiImplicitParam(name = "appointmentId", value = "服务预约id")
    public Result getAppointmentItem(Integer appointmentId) throws Exception {
        return Result.succeed("success", null, appointmentItemService.getAppointmentItem(appointmentId));
    }

    @PostMapping("/startServiceItem")
    @ApiOperation("开始一个服务项目")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "itemId", value = "服务预约项目id"),
            @ApiImplicitParam(name = "operator", value = "操作人")
    })
    public Result startServiceItem(Integer itemId, String operator) throws Exception {
        appointmentItemService.startServiceItem(itemId, operator);
        return Result.succeed("开始服务成功");
    }

    @PostMapping("/endServiceItem")
    @ApiOperation("结束一个服务项目")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "itemId", value = "服务预约项目id"),
            @ApiImplicitParam(name = "operator", value = "操作人")
    })
    public Result endServiceItem(Integer itemId, String operator) throws Exception {
        appointmentItemService.endServiceItem(itemId, operator);
        return Result.succeed("结束服务成功");
    }

}

